package app

import (
	"chatgpt/model/base"
	"github.com/slclub/go-tips"
)

type Price struct {
	base.ModelID
	ProcID    int `gorm:"index;column:proc_id;default:0;comment:商品ID;"`
	Price     int `gorm:"type:int(10);default:0;comment:价格"`
	Origin    int `gorm:"type:int(4);default:0;comment:1=原价，2=打折后价格"`
	StartAt   int `gorm:"type:int(10);default:0;comment:有效开始时间"`
	ExpiredAt int `gorm:"type:int(10);default:0;comment:过期时间"`
	base.ModelTime
}

func (self *Price) TableName() string {
	return "gpt_price"
}

func (self *Price) ConvFromMap(m map[string]any) {
	if val, ok := m["ProcID"]; ok {
		self.ProcID = tips.Int(val)
	}
	if val, ok := m["Price"]; ok {
		self.Price = tips.Int(val)
	}
	if val, ok := m["Origin"]; ok {
		self.Origin = tips.Int(val)
	}
	if val, ok := m["StartAt"]; ok {
		self.StartAt = tips.Int(val)
	}
	if val, ok := m["ExpiredAt"]; ok {
		self.ExpiredAt = tips.Int(val)
	}
	self.ModelID.ConvFromMap(m)
	self.ModelTime.ConvToMap(m)
}

func (self *Price) ConvToMap() map[string]any {
	rtn := map[string]any{
		"ID":        self.ID,
		"ProcID":    self.ProcID,
		"Price":     self.Price,
		"Origin":    self.Origin,
		"StartAt":   self.StartAt,
		"ExpiredAt": self.ExpiredAt,
	}
	self.ModelTime.ConvToMap(rtn)
	return rtn
}
